<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document 对象</title>
</head>
<body>

    <div id="div1">div1</div>
    <div id="div2">div2</div>
    <div id="div3">div3</div>

    <div class="cls1">div4</div>
    <div class="cls1">div5</div>

    <input type="text" name="username">

    <script>

      //2.根据标签获取
      var divArr = document.getElementsByTagName("div");
      //alert(divArr.length);

      //3.根据class属性名字获取
      var divArr1 = document.getElementsByClassName("cls1");
      //alert(divArr1.length);

      //4.通过name属性获取
      var divArr2 = document.getElementsByName("username");
      //alert(divArr2.length);

      //创建元素
      var table = document.createElement("table");
      alert(table);

    </script>

</body>
</html>